package com.ruoyi.system.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.utils.DateUtils;
import javax.annotation.Resource;
import com.ruoyi.common.utils.mybatisPlus.BaseServiceImpl;
import com.ruoyi.common.utils.mybatisPlus.SearchModel;
import com.ruoyi.system.domain.Question;
import com.ruoyi.system.mapper.QuestionMapper;
import com.ruoyi.system.service.QuestionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.common.utils.SecurityUtils;

/**
 * 问题记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-04
 */
@Service
public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, Question> implements QuestionService {
    @Resource
    private QuestionMapper questionMapper;

    /**
     * 查询问题记录
     * 
     * @param id 问题记录主键
     * @return 问题记录
     */
    @Override
    public Question selectQuestionById(Long id){
        return questionMapper.selectById(id);
    }

    /**
     * 查询问题记录列表
     * 
     * @param question 问题记录
     * @return 问题记录
     */
    @Override
    public IPage<Question> selectQuestionList(SearchModel<Question> question){
        return this.page(question);
    }

    /**
     * 批量新增问题记录列表信息
     *
     * @param list<Question> 问题记录对象
     */
    @Transactional
    public boolean insertBatchQuestion(List<Question> list){
        return this.saveBatch(list);
    }

    /**
     * 新增问题记录
     * 
     * @param question 问题记录
     * @return 结果
     */
    @Override
    public int insertQuestion(Question question){
        String username = SecurityUtils.getUsername();
        question.setCreateBy(username);
        question.setCreateTime(DateUtils.getNowDate());
        return questionMapper.insert(question);
    }

    /**
     * 修改问题记录
     * 
     * @param question 问题记录
     * @return 结果
     */
    @Override
    public int updateQuestion(Question question){
        String username = SecurityUtils.getUsername();
        question.setUpdateBy(username);
        question.setUpdateTime(DateUtils.getNowDate());
        return questionMapper.updateById(question);
    }

    /**
     * 批量删除问题记录
     * 
     * @param ids 需要删除的问题记录主键
     * @return 结果
     */
    @Override
    public boolean deleteQuestionByIds(List<Long> ids){
        return this.removeByIds(ids);
    }

    /**
     * 删除问题记录信息
     * 
     * @param id 问题记录主键
     * @return 结果
     */
    @Override
    public int deleteQuestionById(Long id){
        return questionMapper.deleteById(id);
    }

}
